package juc.Future;

import java.util.concurrent.*;

/**
 * Created by svenl on 7/18/2017.
 */
public class TestCallable {
    public static void main(String[] args) throws ExecutionException, InterruptedException {


      /*
        //Future
         ExecutorService fixedThreadPool = Executors.newFixedThreadPool(5);
      Callable callable = new MyCallable();
        Future future = fixedThreadPool.submit(callable);

        System.out.println(future.get());

        fixedThreadPool.shutdown();*/

        //Future task
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        FutureTask<Integer> futureTask = new FutureTask<>(() -> {
            Thread.sleep(10000);
            return 998;
        });

        executorService.execute( futureTask );
        executorService.shutdown();
        Integer integer = futureTask.get();
        System.out.println(integer);


    }
}
